home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1721_Encoding_Foundation_classes_with_Distributed_Objects.rtfd / FoundationExtensions.m < prev    next >
Text File  |  1995-05-08  |  2KB  |  82 lines

  1. /*
  2.  *  Categories on NSArray and NSDictionary that allow them to be
  3.  *  sent over the wire like a regular object.  Currently only NSString,
  4.  *  NSData and NSNumber implement the NXTransport protocol so only those
  5.  *  classes can be sent by value over the wire.
  6.  *
  7.  *  No guarantee is made for the fitness of this code for any particular
  8.  *  use.  No warranty expressed or implied.  Use at your own risk!
  9.  *
  10.  *  Randy Tidd
  11.  *  NeXT Premium Developer Support
  12.  */
  13. #import "FoundationExtensions.h"
  14. #import "FoundationExtensionsPrivate.h"
  15. #import <remote/transport.h>
  16. #import <foundation/NSException.h>
  17. #import <foundation/NSObject.h>
  18.  
  19. @implementation NSObject (OldDOExtensions)
  20.  
  21. /*
  22.  *  The +name and -name categories are necessary because the DO system
  23.  *  sometimes asks a class for it's name for error messages.  You may
  24.  *  already have this category defined in your code, in which case you
  25.  *  should remove one of them.
  26.  */
  27. + (const char *)name
  28. {
  29.     return [[self description] cString];
  30. }
  31.  
  32. - (const char *)name
  33. {
  34.     return [[self description] cString];
  35. }
  36.  
  37. /*
  38.  *  These encodeUsing: and decodeUsing: categories are necessary because in some
  39.  *  circumstances, DO asks an object that is to be encoded bycopy if it responds to
  40.  *  these methods.  However, the methods are never sent, they should never be sent
  41.  *  to an NSObject, thus these implementations just raise an exception.
  42.  *
  43.  *  encodeRemotelyFor:freeAfterEncoding:isBycopy: should be implemented for all
  44.  *  NSObject subclasses, and that, in addition to the two methods below, will
  45.  *  make all NSObjects implement the NXTransport protocol.
  46.  */
  47. - encodeUsing:sender
  48. {
  49.     [NSException raise:NSInternalInconsistencyException
  50.        format:@"*** Attempt to encode an NSObject with old DO: this is not supported!"];
  51.     return self;
  52. }
  53.  
  54. - decodeUsing:sender
  55. {
  56.     [NSException raise:NSInternalInconsistencyException
  57.        format:@"*** Attempt to decode an NSObject with old DO: this is not supported!"];
  58.     return self;
  59. }
  60.  
  61. @end
  62.  
  63. @implementation NSArray (OldDOExtensions)
  64.  
  65. - encodeRemotelyFor:connection freeAfterEncoding:(BOOL *)flag isBycopy:(BOOL)isBycopy
  66. {
  67.     *flag = YES;
  68.     return [[_NSArrayPlaceHolder alloc] initWithArray:self];
  69. }
  70.  
  71. @end
  72.  
  73. @implementation NSDictionary (OldDOExtensions)
  74.  
  75. - encodeRemotelyFor:connection freeAfterEncoding:(BOOL *)flag isBycopy:(BOOL)isBycopy
  76. {
  77.     *flag = YES;
  78.     return [[_NSDictionaryPlaceHolder alloc] initWithDictionary:self];
  79. }
  80.  
  81. @end
  82.